<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.util.*" %>
<%@ page import="com.ionglobal.db.*" %>
<%@ page import="com.ionglobal.lib.*" %>
<%@ page import="com.ionglobal.cms.*" %>
<%@ page import="com.ionglobal.misc.*" %>

<%@ include file="../init_include.jsp" %>

<%
	int catid=0;
	int totalpages,pageid=0;
	int pagerows=Page.getPageRows();
	int totalArchives=0;
	int titleMaxLen=20;
    String ordermode="desc";
    String orderfield="id";
  			
	int check_rst=Permission.accept(dbi,session,request,"sysop","tree","catid","000000010"); 
	if (check_rst!=Permission.CHECK_RST_SUCCESS) {
		if (check_rst==Permission.CHECK_RST_DENY) {
			int checkcat_rst=Permission.accept(dbi,session,request,"sysop","tree","catid","000000010"); 
			if (checkcat_rst!=Permission.CHECK_RST_SUCCESS) {
				dbi.closeAll();				
				response.sendRedirect("../deny.html");			
			} else {
				response.sendRedirect("../sys/showCateInfo.jsp?catid="+request.getParameter("catid"));			
			}
		}
		else {
			dbi.closeAll();		
			response.sendRedirect("../index.jsp");
		}
		return;		
	}
	
	String a=request.getParameter("catid");
	String str="";
	try {
		catid=Integer.parseInt(a);		
	}	catch(NumberFormatException e) {
		out.println(e+"catId");
		return;
	}

	Sysop sysop=(Sysop)session.getAttribute("sysop");
	Vector tree=(Vector)session.getAttribute("tree");
	String permissionStr=Permission.getPermissionStr(dbi,session,catid);
	boolean CanItemBro=PermissionItem.Can(permissionStr,PermissionItem.ItemBro);
	boolean CanItemAdd=PermissionItem.Can(permissionStr,PermissionItem.ItemAdd);
	boolean CanItemDel=PermissionItem.Can(permissionStr,PermissionItem.ItemDel);
	boolean CanItemCheck=PermissionItem.Can(permissionStr,PermissionItem.ItemCheck);
	boolean CanItemEdit=PermissionItem.Can(permissionStr,PermissionItem.ItemEdit);
	boolean CanCategoryBro=PermissionItem.Can(permissionStr,PermissionItem.CategoryBro);

	if(request.getParameter("ordermode")!=null)
		ordermode=request.getParameter("ordermode");	
	if(request.getParameter("orderfield")!=null)
		orderfield=request.getParameter("orderfield");		

	String whereClause="";
	if(request.getParameter("whereClause")!=null)
		whereClause=request.getParameter("whereClause");	
	whereClause=whereClause.trim();

		
	try {
		if (request.getParameter("pageid")!=null)
			pageid=Integer.parseInt(request.getParameter("pageid"));
		else
			pageid=1;
	}	catch(NumberFormatException e) {
		out.println(e+"pageid");
		pageid=1;
	}	
	
	try {
		if (request.getParameter("pagerows")!=null)
			pagerows=Integer.parseInt(request.getParameter("pagerows"));
	} catch(NumberFormatException e) {
		out.println(e+"pagerows");
	}	

	Category cat=new Category(dbi,catid);
	a=cat.getName();
	totalArchives=Archive.getArchivesNums(dbi,catid,whereClause);
	totalpages = (int)Math.ceil((double)totalArchives/pagerows);
	if(pageid>totalpages)
		pageid=totalpages;
	if(pageid<=1)
		pageid=1;
	
	CategoryInfo cinfo=new CategoryInfo("cms",catid);
	String ArchiveItem[]=cinfo.getNewName();
%>	
<html>
<head>
<title><%=ArchiveItem[0]%> <%=Language.getNameByCode("sys.common.manage"," Manage")%></title>
<meta http-equiv="Content-Type" content="text/html; charset=<%=Language.getHTMLLanguageStr()%>">
<link rel="stylesheet" href="../css.css" type="text/css">
<SCRIPT language=JavaScript1.2 src="../script/Ion_Show.js"></SCRIPT>
<script language="javascript">
<!--

	<%if(CanItemAdd) {%>	
	function Ion_Add() {
		addIon('vmsSelectFrame.jsp','../cms/archive_dj.jsp','<%=ArchiveItem[0]%>');
	}	
	<%}%>	
	
	<%if(CanItemDel) {%>	
	function Ion_Del() {
		deleteIon('vmsSelectFrame.jsp','../cms/archive_delete.jsp','<%=ArchiveItem[0]%>');		
	}	
	<%}%>	
	
	<%if(CanItemEdit) {%>	
	function Ion_Edit() {
		editIon('vmsSelectFrame.jsp','../cms/archive_dj.jsp','<%=ArchiveItem[0]%>');
	}		
	<%}%>	
	
	<%if(CanItemBro) {%>	
	function Ion_View() {
		editIon('vmsSelectFrame.jsp','../cms/archive_view.jsp','<%=ArchiveItem[0]%>');
	}		
	<%}%>	

	<%if(CanCategoryBro) {%>	
	function CopyCategory(hrefstr,actionurl,titlename,name,feature) 
	{
		Copy_Category(hrefstr,actionurl,titlename,name,feature,"cms");
	}

	function ChangeCategory(hrefstr,actionurl,titlename,name,feature) 
	{
		Change_Category(hrefstr,actionurl,titlename,name,feature,"cms");
	}
	
	function showCate()
	{
		location.href="../sys/showCateInfo.jsp?catid="+window.formIon.catid.value;
	}
	<%}%>	
	
	function Ion_Search()
	{
		add_Ion('vmsSelectFrame.jsp','../cms/archive_search.jsp','<%=ArchiveItem[0]%>');
	}
	
-->
</script>
</head>

<body bgColor=#d6d3ce leftMargin=0 
style="BORDER-BOTTOM: 0px outset; BORDER-LEFT: 0px outset; BORDER-RIGHT: 0px outset; BORDER-TOP: 0px outset" 
topMargin=0>

<FORM name="formIon" method="post" action="showArchiveInfo.jsp" onsubmit="">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
    <td class="nagivation" colspan="2"><%=Language.getNameByCode("sys.CurrentPos","Current Position")%>:
    <% 
    Vector vcpath=Category.getLadder(session,"tree",catid);
		out.print(Category.getFullPath(vcpath));
		%>
		</td>
  </tr>
	<tr>
 	 <td align="left"><%=ArchiveItem[0]%> <%=Language.getNameByCode("sys.list"," List")%><%=PageStr.getPageHead(totalArchives,pageid,pagerows,totalpages)%>
 	 &nbsp;&nbsp;<% if(whereClause!=null && whereClause.length()>0) {%><a href="javascript:stopSearch();"><%=Language.getNameByCode("sys.clearsearch","Clear Search Condition")%></a><%}%>
 	 </td>
 	 <td align=right>
   	<%=PageStr.PageForm(pageid,totalpages)%><input type="submit" name="Submit" value="go" style="width:0">
   </td>
  </tr>
</table>

	<TABLE border=0 cellPadding=0 cellSpacing=1 height="100%" width="100%">
		<input type="hidden" name="catid" value="<%=catid%>">
		<input type="hidden" name="id" value="<%=catid%>">
		<input type="hidden" name="whereClause" value="<%=whereClause%>">		
		<INPUT name="objid" type="hidden">
		<INPUT name="objtext" type="hidden">
		<INPUT name="objflag" type="hidden">
		<INPUT name="actionurl" type="hidden">
		<input type="hidden" name="orderfield" value="<%=orderfield%>">
		<input type="hidden" name="ordermode" value="<%=ordermode%>">
  	<TR>
    <TD>
    <%
    Table table=new Table();
    table.setSortMode(ordermode);
    table.setSortField(orderfield);
    table.setSelectionMode("multiple");

    table.addColumn("no","id",0,"center","left","number");
    table.addColumn(Language.getNameByCode("cms.id","ID"),"id",30,"center","left","text");
    table.addColumn(ArchiveItem[1],"title",250,"center","left","text");
    table.addColumn(Language.getNameByCode("cms.owner","Owner"),"cruser",60,"center","left","text");
    table.addColumn(Language.getNameByCode("cms.createdate","Create Date"),"crdate",80,"center","center","text");
    table.addColumn(Language.getNameByCode("cms.mender","mender"),"udtuser",60,"center","left","text");
    table.addColumn(Language.getNameByCode("cms.updatedate","Update Date"),"udtdate",80,"center","center","text");
    table.addColumn(Language.getNameByCode("sys.hits","Hits"),"hits",40,"center","center","text");
    table.addColumn(Language.getNameByCode("cms.hot","Hot"),"hot",40,"center","center","number");
    table.addColumn(Language.getNameByCode("cms.ordernum","OrderNum"),"ordernum",40,"center","righ","text");
    table.addColumn(Language.getNameByCode("cms.status","Status"),"status",40,"center","center","number");

    ArrayList rowsList=new ArrayList();	
    try {
	 Vector vc=Archive.getArchives(dbi,whereClause,catid,pageid,pagerows,orderfield,ordermode);
     String rowData="";
   	 String statusstr[]=StaticDim.getArchiveStatus();
     for(int i=0;i<vc.size();i++) {
      Archive ar=(Archive)vc.get(i);
      rowData=ar.getId()+"|"+ar.getId()+"|"+ar.getTitle()+"|"+ar.getCreateUser()+"|"+ar.getCreateDate()+"|"+(ar.getUdtUser().length()>0?ar.getUdtUser():" ")+"|"+(ar.getUdtDate()==null?"":""+ar.getUdtDate())+"|"+ar.getHits()+"|"+(ar.getHot()?Language.getNameByCode("sys.true","true"):Language.getNameByCode("sys.false","false"))+"|"+ar.getOrderNum()+"|"+statusstr[ar.getStatus()];
      rowsList.add(rowData);
     }
    } catch(Exception E) {
    }

	int count=0;
    ArrayList menuList=new ArrayList();
    TableMenu tm=null;
	if(CanItemEdit) {
	    tm=new TableMenu(Language.getNameByCode("cms.Edit","Edit Selected ")+ArchiveItem[0],"javascript:Ion_Edit();",false);
    	menuList.add(tm);
		count++;
	}
	if(CanItemAdd) {
		tm=new TableMenu(Language.getNameByCode("cms.Add","Add New ")+ArchiveItem[0],"javascript:Ion_Add();",false);
		menuList.add(tm);
		count++;
	}
	if(CanItemAdd || CanItemEdit) {
		tm=new TableMenu("","",true);
		menuList.add(tm);
	}
	if(CanItemAdd || CanItemEdit ||  CanItemBro) {
		tm=new TableMenu(Language.getNameByCode("sys.View","View ")+ArchiveItem[0],"javascript:Ion_View();",false);
		menuList.add(tm);
		count++;    
		tm=new TableMenu(Language.getNameByCode("cms.search","Search ")+ArchiveItem[0],"javascript:Ion_Search();",true);
		menuList.add(tm);
		count++;
	}
	if(CanItemAdd || CanItemEdit) {
		tm=new TableMenu(Language.getNameByCode("cms.ChangeOrder","Change It's OrderNum"),"javascript:changeOrder('vmsSelectFrame.jsp','archive_showorder.jsp','"+ArchiveItem[0]+"','','','&orderfield="+orderfield+"&ordermode="+ordermode+"');",false);
		menuList.add(tm);
		count++;
		tm=new TableMenu(Language.getNameByCode("cms.ChangeDate","Change It's Date"),"javascript:changeOrder('vmsSelectFrame.jsp','archive_showDate.jsp','"+ArchiveItem[0]+"');",false);
		menuList.add(tm);
		count++;
		tm=new TableMenu(Language.getNameByCode("cms.SeeBBs","View BBS about"),"javascript:seeBBS('../guestbook/showArchiveInfo.jsp','"+ArchiveItem[0]+"','cms')",false);
		menuList.add(tm);
		count++;
	}
	if(CanItemCheck) {
		tm=new TableMenu(ArchiveItem[0]+Language.getNameByCode("cms.Check"," Check"),"javascript:check('vmsSelectFrame.jsp','archive_check.jsp','"+ArchiveItem[0]+"');",false);
		menuList.add(tm);
		count++; 
		tm=new TableMenu(Language.getNameByCode("cms.ChangeGroup","Change It's Group"),"javascript:check('vmsSelectFrame.jsp','select_single_class.jsp','"+ArchiveItem[0]+"');",false);
		menuList.add(tm);
		count++;
	}
    tm=new TableMenu(Language.getNameByCode("cms.ListReadHistory","List Read History"),"javascript:editIon('vmsSelectFrame.jsp','../cms/Read_history_list.jsp','"+ArchiveItem[0]+"');",true);
    menuList.add(tm);
	count++;
    tm=new TableMenu(Language.getNameByCode("sys.Head.Refresh","Refresh"),"javascript:self.location.reload();",false);
    menuList.add(tm);
	if(CanItemDel) {
//		tm=new TableMenu("","",true);
//		menuList.add(tm);	
		count++;
		tm=new TableMenu(Language.getNameByCode("cms.Delete","Delete Selected ")+ArchiveItem[0],"javascript:Ion_Del();",false);
		menuList.add(tm);
	}

	if(CanCategoryBro) {
		String othermodule=Category.getOtherModule(dbi,catid);
		if(othermodule!=null && othermodule.length()>0){
			othermodule+="|"+cat.getModulecode();
		}else{
			othermodule=cat.getModulecode();
		}
		ArrayList catmenuList=StaticDim.getCategoryMenu(ArchiveItem[0],"cms",othermodule,catid);
		for(int i=0;i<catmenuList.size();i++){
			menuList.add(catmenuList.get(i));
		}
	}

    table.setTableMenu(menuList);
    table.setRowsList(rowsList);
    TableDB tdb=new TableDB();
    out.print(tdb.draw(table));
    %>
    </TD>
 	</TR>
	</TABLE>
</FORM>
</body>
</html>
<%@ include file="../init_free.jsp" %>